from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-29 14:06:01.193929
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 29, Jan, 2022
Time: 14:06:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8907
Nobs: 551.000 HQIC: -48.3197
Log likelihood: 6441.39 FPE: 7.86153e-22
AIC: -48.5949 Det(Omega_mle): 6.68661e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348789 0.069794 4.997 0.000
L1.Burgenland 0.106693 0.042384 2.517 0.012
L1.Kärnten -0.110667 0.022014 -5.027 0.000
L1.Niederösterreich 0.198047 0.088658 2.234 0.025
L1.Oberösterreich 0.131073 0.087621 1.496 0.135
L1.Salzburg 0.254533 0.044804 5.681 0.000
L1.Steiermark 0.035251 0.059088 0.597 0.551
L1.Tirol 0.098359 0.047704 2.062 0.039
L1.Vorarlberg -0.072090 0.042148 -1.710 0.087
L1.Wien 0.017359 0.077981 0.223 0.824
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054544 0.151278 0.361 0.718
L1.Burgenland -0.041024 0.091868 -0.447 0.655
L1.Kärnten 0.040531 0.047716 0.849 0.396
L1.Niederösterreich -0.203367 0.192164 -1.058 0.290
L1.Oberösterreich 0.455622 0.189917 2.399 0.016
L1.Salzburg 0.283169 0.097113 2.916 0.004
L1.Steiermark 0.115778 0.128073 0.904 0.366
L1.Tirol 0.305845 0.103397 2.958 0.003
L1.Vorarlberg 0.023143 0.091354 0.253 0.800
L1.Wien -0.024677 0.169022 -0.146 0.884
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195241 0.035476 5.503 0.000
L1.Burgenland 0.090726 0.021544 4.211 0.000
L1.Kärnten -0.007409 0.011190 -0.662 0.508
L1.Niederösterreich 0.236684 0.045064 5.252 0.000
L1.Oberösterreich 0.168648 0.044538 3.787 0.000
L1.Salzburg 0.038446 0.022774 1.688 0.091
L1.Steiermark 0.025284 0.030034 0.842 0.400
L1.Tirol 0.080889 0.024248 3.336 0.001
L1.Vorarlberg 0.055361 0.021424 2.584 0.010
L1.Wien 0.117865 0.039638 2.974 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118079 0.035636 3.313 0.001
L1.Burgenland 0.043594 0.021641 2.014 0.044
L1.Kärnten -0.013811 0.011240 -1.229 0.219
L1.Niederösterreich 0.172357 0.045267 3.808 0.000
L1.Oberösterreich 0.335165 0.044738 7.492 0.000
L1.Salzburg 0.099652 0.022876 4.356 0.000
L1.Steiermark 0.109526 0.030170 3.630 0.000
L1.Tirol 0.090507 0.024357 3.716 0.000
L1.Vorarlberg 0.060667 0.021520 2.819 0.005
L1.Wien -0.016015 0.039816 -0.402 0.688
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125480 0.067247 1.866 0.062
L1.Burgenland -0.047942 0.040837 -1.174 0.240
L1.Kärnten -0.045527 0.021211 -2.146 0.032
L1.Niederösterreich 0.140634 0.085421 1.646 0.100
L1.Oberösterreich 0.167778 0.084423 1.987 0.047
L1.Salzburg 0.283640 0.043169 6.570 0.000
L1.Steiermark 0.058681 0.056931 1.031 0.303
L1.Tirol 0.155002 0.045962 3.372 0.001
L1.Vorarlberg 0.094205 0.040609 2.320 0.020
L1.Wien 0.071552 0.075134 0.952 0.341
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080118 0.052424 1.528 0.126
L1.Burgenland 0.023907 0.031836 0.751 0.453
L1.Kärnten 0.053335 0.016535 3.226 0.001
L1.Niederösterreich 0.193264 0.066592 2.902 0.004
L1.Oberösterreich 0.329527 0.065813 5.007 0.000
L1.Salzburg 0.033495 0.033653 0.995 0.320
L1.Steiermark 0.003474 0.044382 0.078 0.938
L1.Tirol 0.120114 0.035831 3.352 0.001
L1.Vorarlberg 0.065955 0.031658 2.083 0.037
L1.Wien 0.098602 0.058573 1.683 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174272 0.063398 2.749 0.006
L1.Burgenland 0.003358 0.038500 0.087 0.931
L1.Kärnten -0.065656 0.019997 -3.283 0.001
L1.Niederösterreich -0.109487 0.080532 -1.360 0.174
L1.Oberösterreich 0.215887 0.079591 2.712 0.007
L1.Salzburg 0.053184 0.040698 1.307 0.191
L1.Steiermark 0.249582 0.053673 4.650 0.000
L1.Tirol 0.498307 0.043332 11.500 0.000
L1.Vorarlberg 0.064304 0.038285 1.680 0.093
L1.Wien -0.080066 0.070834 -1.130 0.258
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156904 0.070163 2.236 0.025
L1.Burgenland -0.004250 0.042608 -0.100 0.921
L1.Kärnten 0.062092 0.022131 2.806 0.005
L1.Niederösterreich 0.181686 0.089126 2.039 0.041
L1.Oberösterreich -0.066317 0.088084 -0.753 0.452
L1.Salzburg 0.205653 0.045041 4.566 0.000
L1.Steiermark 0.138690 0.059400 2.335 0.020
L1.Tirol 0.056496 0.047956 1.178 0.239
L1.Vorarlberg 0.142537 0.042370 3.364 0.001
L1.Wien 0.129835 0.078393 1.656 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395256 0.040911 9.661 0.000
L1.Burgenland -0.002824 0.024844 -0.114 0.909
L1.Kärnten -0.020749 0.012904 -1.608 0.108
L1.Niederösterreich 0.202568 0.051968 3.898 0.000
L1.Oberösterreich 0.241953 0.051360 4.711 0.000
L1.Salzburg 0.033412 0.026263 1.272 0.203
L1.Steiermark -0.017894 0.034635 -0.517 0.605
L1.Tirol 0.086860 0.027962 3.106 0.002
L1.Vorarlberg 0.051163 0.024705 2.071 0.038
L1.Wien 0.033967 0.045709 0.743 0.457
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035234 0.102489 0.166419 0.133327 0.093480 0.081209 0.029457 0.211957
Kärnten 0.035234 1.000000 -0.025405 0.133355 0.046778 0.086221 0.444721 -0.068316 0.093239
Niederösterreich 0.102489 -0.025405 1.000000 0.309942 0.124478 0.268202 0.067791 0.156829 0.281632
Oberösterreich 0.166419 0.133355 0.309942 1.000000 0.214879 0.292848 0.169902 0.134069 0.236400
Salzburg 0.133327 0.046778 0.124478 0.214879 1.000000 0.124653 0.089120 0.103517 0.126693
Steiermark 0.093480 0.086221 0.268202 0.292848 0.124653 1.000000 0.135021 0.105750 0.029782
Tirol 0.081209 0.444721 0.067791 0.169902 0.089120 0.135021 1.000000 0.063553 0.150751
Vorarlberg 0.029457 -0.068316 0.156829 0.134069 0.103517 0.105750 0.063553 1.000000 -0.004811
Wien 0.211957 0.093239 0.281632 0.236400 0.126693 0.029782 0.150751 -0.004811 1.000000